﻿using FairyGUI;

/// <summary>
/// 语音提示
/// </summary>
public class UIGameVoice
{
	static UIGameVoice _inst;
	public static UIGameVoice inst { get {  return _inst; } }

	GComponent _uiComp;
	GImage[] _vs;

	public UIGameVoice (GComponent uiComp)
	{
		_uiComp = uiComp;

		_vs = new GImage[5];
		for (int i = 1; i <= 5; ++i) {
			_vs [i - 1] = uiComp.GetChild ("v" + i).asImage;
		}

		SetVoice (0);
		_inst = this;
	}

	public bool visible {
		set {
			_uiComp.visible = _uiComp.enabled = value;
		}
	}

	public void BeginVoice ()
	{
		DebugInfo.Log ("开始录音");

		VoiceChat.inst.BeginRecord ();
	}

	public void EndVoice (bool ok)
	{
		DebugInfo.Log (ok ? "结束录音" : "取消录音");

		if (ok) {
			VoiceChat.inst.EndRecord ();
		} else {
			VoiceChat.inst.CancelRecord ();
		}
	}

	public void SetVoice(int value) {
		int showNum = value / 20;
		for (int i = 1; i <= 5; ++i) {
			_vs [i - 1].visible = (showNum > 0);
			showNum -= 1;
		}
	}
}
